/*
 ============================================================================
 Name		: RSSXmlParser.h
 Author	  : JohnLZeng
 Version	 : 1.0
 Copyright   : Your copyright notice
 Description : CRSSXmlParser declaration
 ============================================================================
 */

#ifndef RSSXMLPARSER_H
#define RSSXMLPARSER_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include "XmlParseNotify.h"
#include "DefaultDocHandler.h"
#include "DefaultDeclHandler.h"

_LIT(KRSSXmlTagItem,	"item");	
_LIT(KRSSXmlTagTitle,	"title");	
_LIT(KRSSXmlTagLink,	"link");	
_LIT(KRSSXmlTagPubDate,	"pubdate");	
_LIT(KRSSXmlTagContentEncoded,"encoded");	//content:encoded
//_LIT(KRSSXmlTag,"");	

enum TRSSXmlTagType
	{
	ERSSXmlTagNone = 0,
	ERSSXmlTagItem,
	ERSSXmlTagTitle,
	ERSSXmlTagLink,
	ERSSXmlTagPubDate,
	ERSSXmlTagContentEncoded,
	};
// CLASS DECLARATION
class CDocXmlParser;
/**
 *  CRSSXmlParser
 * 
 */
class CRSSXmlParser : public CBase, public CDefaultDocHandler
	{
public:
	// Constructors and destructor

	/**
	 * Destructor.
	 */
	~CRSSXmlParser();

	/**
	 * Two-phased constructor.
	 */
	static CRSSXmlParser* NewL();

	/**
	 * Two-phased constructor.
	 */
	static CRSSXmlParser* NewLC();

private:

	/**
	 * Constructor for performing 1st stage construction
	 */
	CRSSXmlParser();

	/**
	 * EPOC default constructor for performing 2nd stage construction
	 */
	void ConstructL();
	
	//
public:  //CDefaultDocHandler
	void StartElement(const TQualified& aName, const RArray<TAttribute>& aAttributes);
	void EndElement(const TQualified& aName);
	void CharacterData(const TDesC& aData);
	void StartCDataSection();
	void EndCDataSection();
	
public:
	void Parse(const TDesC8& aBuffer);
	void ParseFile(const TDesC& aFileName);
	
	void SetParseNotify(MRSSXmlParseNotify* aParseNotify) {iParseNotify = aParseNotify;};

	void Clear();
private:
	TInt ConvertTagToNumber(const TDesC& aTag);
	void PushTag(const TInt aTag);
	void PopTag();
	TInt StackTag();
	TInt StackParentTag(TInt aLevel);
	
	void ParseTagItem();
	void EndParseTagItem();
	
	void ParseDataTitle(const TDesC& aData);
	
	void ParseDataContent(const TDesC& aData);	
	void EndParseContent();
	
private:
	CDocXmlParser*		iDocParser;
	MRSSXmlParseNotify* iParseNotify;	//not owned
	
	RArray<TInt>	iTagStack;
	CRSSBriefData*	iRSSBriefItem;		//not owned
	
	HBufC8*		iContent;
	};

#endif // RSSXMLPARSER_H
